import React from 'react';
import { List } from 'antd-mobile';
const { Item } = List;
export default function MemberInfo(member) {
    // face pulse tongue alpha 接口返回的数据中没有改字段(Relation)。
    window.scrollTo(0, 0);
    let Birth, create;
    if(member.birthday){
        Birth = member.birthday.replace(/-/g, "/");//在iOS 上的兼容处理
    }
    if(member.createTime){
        create = member.createTime.replace(/-/g, "/");
    }

    let Agetime = member.age;
    let Ages = "", time = new Date(create),times = new Date(Birth);
    let newYear = time.getFullYear(), oldYear = times.getFullYear();
    let newMonth = time.getMonth()+1; let oldMonth = parseInt(times.getMonth())+1;
    let newDay = time.getDate(), oldDay = times.getDate();
    let year = newYear - oldYear,Today = newDay - oldDay, month = newMonth - oldMonth;
    if(Agetime >= 1){
       Ages = Agetime + '岁'
    }else{
       if(year == 0){
         if(month >= 1){  
               Ages = month+ '月';  
          }else{
            if(month < 1&&Agetime <=0){
               Ages = Today+ '天';
            }
          }
       }else{
          let m1 = 12 - oldMonth;
          let r1 = 31 - oldDay;
          Ages = m1 + newMonth + '月' ;
          if(m1 == 0){
            if (newMonth ==1 ) {
              Ages = r1 + newDay;
              if (Ages>=31) {
                Ages = 1+'月';
              }else{
                Ages += '天';
              }
            }
          }
          
       }
    }
  return (
    <List>
      <Item>
        <span style={{ marginRight: 20 }}>
          {member.name}
        </span>
        {member.relation ? (<small>({member.relation})</small>) : ""}
        <span style={{ margin: '0 30px' }}>
          {member.gender == 1? "男":"女"}
        </span>
        <span>{Ages}</span>
        <span style={{ float: 'right'}}>{member.extra || member.CreateTime || member.Createtime }</span>
      </Item>
    </List>
  );
}
